from django.db import models

# Create your models here.

class Item(models.Model):
    name = models.CharField(max_length=100)
    description = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.name
#一对一关系
class Performer(models.Model):
    id=models.IntegerField(primary_key=True)
    name=models.CharField(max_length=20)
    nationality=models.CharField(max_length=20)
    masterpiece=models.CharField(max_length=50)
    
class Performer_info(models.Model):
    id=models.IntegerField(primary_key=True)
    performer=models.OneToOneField(Performer,on_delete=models.CASCADE)
    birth=models.CharField(max_length=20)
    elapse=models.CharField(max_length=20)

#一对多关系 
class Program(models.Model):
    id=models.IntegerField(primary_key=True)
    performer=models.ForeignKey(Performer,on_delete=models.CASCADE)
    name=models.CharField(max_length=20)
#多对多关系
    
class Movie(models.Model):
    id=models.IntegerField(primary_key=True)
    name=models.CharField(max_length=20)
    performer=models.ManyToManyField(Performer)

class PersonInfo(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=20)
    age = models.IntegerField()
    hireDate = models.DateField()

    def __str__(self):
        return self.name
    class Meta:
        verbose_name='人员信息'

class Vocation(models.Model):
    id = models.AutoField(primary_key=True)
    job = models.CharField(max_length=20)
    title =models.CharField(max_length=20)
    payment = models.IntegerField(null=True, blank=True)
    name=models.ForeignKey(PersonInfo,on_delete=models.Case)
    def __str__(self):
        return str(self.id)
    class Meta:
        verbose_name='职业信息'